define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Predepositdetails, $timeout, GoPage) {
		
		//初始化
		$scope.init_data = function(){
			Predepositdetails.getList(1,function(data){
				$scope.datas = data;
				console.log(data)
			})
		}
		$scope.init_data();
		
		/****************上下拉刷新****************/
		$scope.isLoad = false; //可以加载
		$scope.nPage = 1;
		$scope.doRefresh = function() {
			//防止重复加载
			$scope.isLoad = true;
			Predepositdetails.getList(1, function(data) {
				$scope.datas = data;
				$scope.nPage = 1;
			},
			function() {
				$scope.$broadcast('scroll.refreshComplete');
				$timeout(function() {
					$scope.isLoad = false;
				}, 1500);
			});
		};
		//加载更多
		$scope.doRefreshMore = function() {
			//防止重复加载
			$scope.isLoad = true;
			Predepositdetails.getList($scope.nPage + 1, function(data) {
				if(data != null) {
					if($scope.datas.advance != undefined) {
						$scope.datas.advance = $scope.datas.advance.concat(data.advance);
						$scope.nPage += 1;
					} else {
						$scope.datas = data;
					}
				}
			},function() {
				$scope.$broadcast('scroll.infiniteScrollComplete');
				$timeout(function() {
					$scope.isLoad = false;
				}, 1500);
			});
		};
		/****************上下拉刷新****************/
		
		//跳转到订单
		$scope.onshow_buyerpayment = function(order_id){
			GoPage.go_states("buyerpayment", {"order_id": order_id});
		}

	}

	controller.$inject = ['$scope', 'Predepositdetails', '$timeout', 'GoPage'];
	
	return app.registerController("predepositdetailsctrl",controller);
});